package org.wk.news.controller;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wk.core.common.view.PageVo;
import org.wk.core.common.view.ResponseVo;
import org.wk.logger.common.annotation.SysLog;
import org.wk.news.service.NewsClassifiedsService;
import org.wk.news.view.NewsClassifiedsVo;
import org.wk.news.view.NewsManageVo;
import org.wk.upms.controller.AbstractController;


import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @ClassName NewsController
 * @Description
 * @Author ZhaoPing'an
 * @Date 2018/6/5 9:07
 */
@RestController
@RequestMapping("/news/classifieds")
public class NewsClassifiedsController extends AbstractController {

    @Autowired
    private NewsClassifiedsService classifiedService;

    /**
     * @Description 资讯类型列表
     * @Param [params]
     * @author ZhaoPing'an
     * @Date 2018/6/5 11:38
     */
    @SysLog("资讯分类列表分页")
    @RequestMapping("/list")
    public ResponseVo list(@RequestParam Map<String, Object> params){
        PageVo page = classifiedService.findClassifiedsListPage(params);
        return ResponseVo.success().addAttribute("page", page);
    }

    /**
     * @Description  保存资讯类型
     * @Param [newsType]
     * @author ZhaoPing'an
     * @Date 2018/6/5 11:47
     */
    @SysLog("保存资讯类型")
    @RequestMapping("/save")
    public ResponseVo save(@RequestBody NewsClassifiedsVo newsClassifiedsVo){
        // 保存
        classifiedService.insert(newsClassifiedsVo);
        return ResponseVo.success();
    }

    /**
     * @Description 获取资讯分类详细信息
     * @Param [id]
     * @author ZhaoPing'an
     * @Date 2018/6/5 15:52
     */
    @SysLog("获取资讯分类详情")
    @RequestMapping("/info/{id}")
    public ResponseVo findNewsClassifiedsInfo(@PathVariable("id")String id){
        NewsClassifiedsVo result = classifiedService.findNewsClassifiedsInfo(id);
        return ResponseVo.success().setData(result);
    }

    @SysLog("修改资讯类型")
    @RequestMapping("/update")
    public ResponseVo update(@RequestBody NewsClassifiedsVo newsClassifiedsVo){
        // 保存
        classifiedService.update(newsClassifiedsVo);
        return ResponseVo.success();
    }

    /**
     * @Description 删除资讯分类
     * @Param [ids]
     * @author ZhaoPing'an
     * @Date 2018/6/5 16:54
     */
    @SysLog("删除资讯分类")
    @RequestMapping("/delete")
    public ResponseVo delete(@RequestBody String[] ids){
        classifiedService.deleteBatchIds(Arrays.asList(ids));
        return ResponseVo.success();
    }

    /**
     * @Description 获取所有资讯分类
     * @Param [params]
     * @author ZhaoPing'an
     * @Date 2018/6/8 9:27
     */
    @SysLog("获取所有资讯分类")
    @RequestMapping("/findAll")
    public ResponseVo findAll(){
        List<NewsClassifiedsVo> list = classifiedService.findAll();
        return ResponseVo.success().addAttribute("list", list);
    }

}
